<template>
    <header class="header">
        <h1>todos</h1>
        <input class="new-todo" placeholder="What needs to be done?" autofocus v-model="ipt" @keydown.enter="add">
    </header>
</template>

<script>
    export default {
        props: ['arr1'],
        data() {
            return {
                ipt: ''
            }
        },
        methods: {
            add(e) {
                if (!e.target.value.trim()) {
                    alert('名称不能是空')
                    return
                }
                this.$emit('add-todo', e.target.value.trim())
                e.target.value = ''
            }
        }
    }
</script>

<style>

</style>